from datetime import datetime, timedelta
import time

# 基础库 datetime

# 当前时间 <class 'datetime.datetime'> 2021-01-06 11:32:25.523447
now_time = datetime.now()
print(now_time)

# 当前时间时间戳float 1610431987.2630384
timestamp = time.time()
print(type(timestamp))

# 当前时间时间戳float 1610431987.2630384
int_timestamp = int(time.time())
print(f"int_timestamp: {int_timestamp}")

# 时间格式化
# 当前时间格式化输出str
datetime.now().strftime("%Y%m%d %H:%M:%S")
# 字符串转换成时间格式
str_to_datetime = datetime.strptime("2017-11-23 16:10:10", "%Y-%m-%d %H:%M:%S")

# 时间计算
time_operation = datetime.now() + timedelta(days=-1)
print(time_operation)
print(type(time_operation))

time1 = datetime.now()
time2 = datetime.strptime("2017-11-23 16:10:10", "%Y-%m-%d %H:%M:%S")
time3 = time1.strftime("%Y-%m-%d %H:%M:%S")

# 时间大小比较
if time1 > time_operation:
    print(123)
else:
    print(456)

